package com.uenpay.im.entities;

import java.io.Serializable;
import java.util.ArrayList;

import org.json.JSONArray;
import org.json.JSONObject;

/**
 * @author SL
 * @created 2016-4-28 下午2:14:45
 * @copyRight http://www.qiyunxin.com
 * @function 新闻实例
 */
public class NewsEntity implements Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	public String createtime;
	public int publicnoid;
	public String thumtitle;
	public String title;
	public String updatetime;
	public int viewcount;
	public String thumimg;
	public int newsid;
	public String url;
	public String bannerimg;

	public static NewsEntity serNewsEntity(JSONObject json) {
		NewsEntity mNewsEntity = new NewsEntity();
		mNewsEntity.newsid = json.optInt("newsid");
		mNewsEntity.createtime = json.optString("createtime");
		mNewsEntity.publicnoid = json.optInt("publicnoid");
		mNewsEntity.thumtitle = json.optString("thumtitle");
		mNewsEntity.title = json.optString("title");
		mNewsEntity.updatetime = json.optString("updatetime");
		mNewsEntity.viewcount = json.optInt("viewcount");
		mNewsEntity.thumimg = json.optString("thumimg");
		mNewsEntity.url = json.optString("url");
		mNewsEntity.bannerimg = json.optString("bannerimg");
		return mNewsEntity;
	}

	/**
	 * 解析新闻数据
	 * 
	 * @param jsonArray
	 * @return
	 */
	public static ArrayList<NewsEntity> serNewsEntitys(JSONArray jsonArray) {
		if (jsonArray == null || jsonArray.length() < 1) {
			return null;
		} else {
			ArrayList<NewsEntity> arrayList = new ArrayList<NewsEntity>();
			for (int i = 0, size = jsonArray.length(); i < size; i++) {
				arrayList.add(serNewsEntity(jsonArray.optJSONObject(i)));
			}
			return arrayList;
		}
	}
}
